package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.EventInfoDto;
import com.crm.jdy.common.dto.PeoductInfoDto;
import com.crm.jdy.common.pojo.EventInfo;
import com.crm.jdy.common.pojo.PeoductInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.EventInfoService;
import com.crm.jdy.service.client.PeoductInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 待办事项API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年3月27日
*
*/
@Validated
@Api(tags = "eventInfo", description ="待办事项")
@RestController
@RequestMapping("/eventInfo")
public class EventInfoController{

    @Reference(version = "${service.version}", check = false)
    EventInfoService eventInfoService;

    @RateLimit()
    @ApiOperation("待办事项信息")
    @PostMapping("/seleteEventInfo")
    public ResultVo seleteEventInfo(@RequestBody EventInfoDto eventInfo){
        PageInfo<EventInfo> list = eventInfoService.seleteEventInfo(eventInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新待办事项")
    @PostMapping("/updateEventInfo")
    public ResultVo updateEventInfo(@ApiParam(value = "eventInfo", required = true)
                                    @Validated @RequestBody EventInfo eventInfo){
        boolean index = eventInfoService.updateEventInfo(eventInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加待办事项")
    @PostMapping("/addEventInfo")
    public ResultVo addEventInfo(@ApiParam(name = "eventInfo", required = false)
                                 @Validated @RequestBody EventInfo eventInfo){
        boolean list  = eventInfoService.addEventInfo(eventInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除待办事项")
    @DeleteMapping("deleteEventInfo/{eveId}")
    public ResultVo deleteEventInfo(@NotNull @ApiParam(name = "eveId", value = "eveId", required = true) @PathVariable String eveId){
        boolean b = eventInfoService.removeEventInfo(eveId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }



}